from django.db import models

# Create your models here.


class UserProfile(models.Model):
    username = models.CharField("用户名", max_length=30, unique=True, null=False, db_index=True)
    password = models.CharField("密码", max_length=32)
    email = models.EmailField("邮箱")
    phone = models.CharField("手机号", max_length=11)
    created_time = models.DateTimeField("创建时间", auto_now_add=True)
    updated_time = models.DateTimeField("修改时间", auto_now=True)


class OrderInfo(models.Model):
    user_profile = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
    total_amount = models.DecimalField("总金额", max_digits=10, decimal_places=2)
    freight = models.DecimalField("运费", max_digits=10, decimal_places=2)
    status = models.IntegerField("订单状态")
    created_time = models.DateTimeField("创建时间", auto_now_add=True)
    updated_time = models.DateTimeField("修改时间", auto_now=True)

    class Meta:
        db_table = "orders_order_table"


class OrderGoods(models.Model):
    order_info = models.ForeignKey(OrderInfo, on_delete=models.CASCADE)
    sku_name = models.CharField("商品名称", max_length=50)
    price = models.DecimalField("单价", max_digits=10, decimal_places=2)
    count = models.IntegerField("数量")

    class Meta:
        db_table = "orders_order_goods"

